@extends('home.parent')
@section('title','关键词列表')
@section('head_js')
@endsection
@section('head_css')
<link rel="stylesheet" href="{{ asset('/css/dataTables.bootstrap.css') }}">
<link rel="stylesheet" href="{{ asset('/css/toggleButtonsMain.css') }}">
@endsection
@section('content')
<div class="content-wrapper">
<section class="content-header">
	<h1>
		关键词列表
		<small></small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="{{URL('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
		<li class="active">关键词列表</li>
	</ol>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-header">
					<div class="form-inline pull-right">
						<fieldset>
							<div class="input-group input-group-sm">
								<span class="input-group-addon"><strong>关键字字段</strong></span>
								<input type="text" class="form-control" id="search_keyword">
							</div>
							<div class="input-group input-group-sm">
								<div class="input-group-btn">
									<button type="button"  class="btn btn-primary" onclick="searchData()"><i class="fa fa-search"></i></button>
								</div>
							</div>
						</fieldset>
					</div>
					<div class="form-inline pull-left">
						<div class="input-group input-group-sm" style="margin-left: 20px;">
							<div class="input-group-btn" >
								<a href="#" class="btn btn-info" onclick="showCreateElement()">新增关键词</a>
							</div>
						</div>
					</div>
				</div>
				<!-- /.box-header -->
				<div class="box-body">
					<table id="data_list" class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>关键词字段</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<?
								if(isset($data['keywords'][0])){
									$i=0;
									foreach($data['keywords'] as $k=>$v){
										?><tr>
											<td><? echo ++$i;?></td>
											<td><? echo $v;?></td>
											<td>
												<a href='javascript:;' onclick="updateModal('<?=$k;?>','<?=$v;?>')" title='修改'><span class='glyphicon glyphicon-pencil'></span></a>
												&nbsp;&nbsp;&nbsp;
												<a href='javascript:void(0);' title='删除' onclick="deletModel('<?=$k?>')"><span class='glyphicon glyphicon-trash'></span></a>
											</td>
										</tr><?
									}
								}else{?>
									<tr><td colspan="3">无数据</td></tr>
								<?}
							?>
						</tbody>
						<tfoot>
							<tr>
								<th>编号</th>
								<th>关键词字段</th>
								<th>操作</th>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>
</div>
<div class="modal fade" id="modal-info">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
				<span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">11</h4>
			</div>
			<div class="modal-body">
				<div class="form-group">
					<label class="">关键字</label>
					<input type="hidden" class="form-control" name="kid" id="kid">
					<input type="text" class="form-control" name="kname" id="kname">
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
				<button type="submit" class="btn btn-primary" onclick="saveData()">保存</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
@endsection
@section('foot_js')
<script src="{{ asset('/js/tools.js') }}"></script>
<script>
//添加关键词显示弹层
function showCreateElement(){
	$("#kid").val('');
	$("#kname").val('');
	$('#modal-info h4').html('添加关键字');
	$('#modal-info').modal();
}

//添加修改关键词保存
function saveData(){
	var kid = $.trim($("#kid").val());
	var kname = $.trim($("#kname").val());
	if(kname == '') {
		layer.msg('请输入关键字',{icon:2});
		return false;
	}
	var url = "{{ URL('admin/keyword/video/save/ajax') }}";
	var data = {kid:kid,kname:kname};
	var result = puppet.myajax('post',url,data,false);
	if(result.code == 1){
		layer.msg('操作失败',{icon:5});
		return false;
	}else{
		layer.msg('操作成功',{icon:6});
		setTimeout('window.location.reload()',2000);
		$('#modal-info').modal('hide');
	}
}
//修改
function updateModal(kid,kname){
	$("#kid").val(kid);
	$("#kname").val(kname);
	$('#modal-info').modal();
	$('#modal-info h4').html('修改关键字');
}
// 删除
function deletModel(kid){
	result = layer.confirm('是否确认删除', {
		btn: ['确认删除', '再考虑一下'] //按钮
	}, function () {
		shanchu(kid);
	});
}
function shanchu(kid) {
	var url = "{{ URL('admin/keyword/video/delet/ajax') }}";
	var data = {kid:kid};
	var result = puppet.myajax('post',url,data,false);
	if(result.code == 1){
		layer.msg(result.msg,{icon:5});
		return false;
	}else{
		layer.msg('删除成功',{icon:6});
		setInterval(function(){
			history.go(0);
		},"2000");
		$('#modal-info').modal('hide');
	}
}
//搜索
function searchData(){
	var kname=$.trim($('#search_keyword').val());
	var url = "{{ URL('admin/keyword/video/list/serach') }}";
	var data={kname:kname};
	var result = puppet.myajax('post',url,data,false);
	if(result.code == 1){
		layer.msg(result.msg,{icon:5});
		return false;
	}else{
		if(result.msg != ''){$('#data_list tbody').html(result.msg);}
		$('#modal-info').modal('hide');
	}
	layer.msg('操作成功',{icon:6});
}
</script>
@endsection